#include "JTAG_DP.h"
#include "dap_setting.h"

void PORT_JTAG_SETUP(void)
{
    pMdLink_DAP_Setting_t dap_setting = get_dap_setting();
    PORT_Mode_t mode = dap_setting->jtag_port_mode;
    switch (mode) {
        case PORT_MODE_GPIO:
            IO_PORT_JTAG_SETUP();
            break;
        case PORT_MODE_DEDIC_GPIO:
            Dedic_IO_PORT_JTAG_SETUP();
            break;
        case PORT_MODE_SPI:
            // SPI_PORT_JTAG_SETUP();
            break;
        default:
            return;
    }
}

void JTAG_Sequence(uint32_t info, const uint8_t *tdi, uint8_t *tdo)
{
    pMdLink_DAP_Setting_t dap_setting = get_dap_setting();
    PORT_Mode_t mode = dap_setting->jtag_port_mode;
    switch (mode) {
        case PORT_MODE_GPIO:
            IO_JTAG_Sequence(info, tdi, tdo);
            break;
        case PORT_MODE_DEDIC_GPIO:
            Dedic_IO_JTAG_Sequence(info, tdi, tdo);
            break;
        case PORT_MODE_SPI:
            //SPI_JTAG_Sequence(info, tdi, tdo);
            break;
        default:
            return;
    }
}

uint32_t JTAG_ReadIDCode(void)
{
    pMdLink_DAP_Setting_t dap_setting = get_dap_setting();
    PORT_Mode_t mode = dap_setting->jtag_port_mode;
    switch (mode) {
        case PORT_MODE_GPIO:
            return IO_JTAG_ReadIDCode();
        case PORT_MODE_DEDIC_GPIO:
            return Dedic_IO_JTAG_ReadIDCode();
        case PORT_MODE_SPI:
            //return SPI_JTAG_ReadIDCode();
        default:
            return 0;
    }
}

void JTAG_WriteAbort(uint32_t data)
{
    pMdLink_DAP_Setting_t dap_setting = get_dap_setting();
    PORT_Mode_t mode = dap_setting->jtag_port_mode;
    switch (mode) {
        case PORT_MODE_GPIO:
            IO_JTAG_WriteAbort(data);
            break;
        case PORT_MODE_DEDIC_GPIO:
            Dedic_IO_JTAG_WriteAbort(data);
            break;
        case PORT_MODE_SPI:
            //SPI_JTAG_WriteAbort(data);
            break;
        default:
            return;
    }
}

void JTAG_IR(uint32_t ir)
{
    pMdLink_DAP_Setting_t dap_setting = get_dap_setting();
    PORT_Mode_t mode = dap_setting->jtag_port_mode;
    switch (mode) {
        case PORT_MODE_GPIO:
            IO_JTAG_IR(ir);
            break;
        case PORT_MODE_DEDIC_GPIO:
            Dedic_IO_JTAG_IR(ir);
            break;
        case PORT_MODE_SPI:
            //SPI_JTAG_IR(ir);
            break;
        default:
            return;
    }
}

uint8_t JTAG_Transfer(uint32_t request, uint32_t *data)
{
    pMdLink_DAP_Setting_t dap_setting = get_dap_setting();
    PORT_Mode_t mode = dap_setting->jtag_port_mode;
    switch (mode) {
        case PORT_MODE_GPIO:
            return IO_JTAG_Transfer(request, data);
        case PORT_MODE_DEDIC_GPIO:
            return Dedic_IO_JTAG_Transfer(request, data);
        case PORT_MODE_SPI:
            //return SPI_JTAG_Transfer(request, data);
        default:
            return 0;
    }
}
